package org.example.provider.filter;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate
public class TestFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        // TODO: recorde span... (org.example.controller.ProviderController)
        Result result = null;
        try {
            result = process(invoker, invocation);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    private Result process(Invoker<?> invoker, Invocation invocation) {
        Result result = null;
        String clientIp = RpcContext.getContext().getRemoteHost();
        result = invoker.invoke(invocation);
        System.out.println("Remote IP: " + clientIp);
        return result;
    }
}
